Use case: HASH process using SHA1 algorithm in polling mode

Sequence diagram

HASH process

  @startuml
    participant "Application" as App
    participant "HASH" as HASH

    == HASH Initialization and Configuration ==
    App -> HASH: HAL_HASH_Init()
    note right : Configure the data type
    App <-- HASH:\n\n
    ==  HASH process with SHA1 algorithm  ==
    group process: oneshot computing with single buffer
    App -> HASH: HAL_HASH_SHA1_Start()
    note right : Compute and read the digest \nfrom the output buffer \nprovided via a pointer
    end
    group process: computing with several input buffers
    App -> HASH: HAL_HASH_SHA1_Accmlt()
    note right : write the first input buffer
    App -> HASH: HAL_HASH_SHA1_Accmlt()
    note right : write the next input buffer
    App -> HASH: HAL_HASH_SHA1_Accmlt_End()
    note right : - feed the last input data buffer \n - retrieve the computed digest \nreturned via a pointer
    end

    == HASH De-initialization  ==
    App -> HASH: HAL_HASH_DeInit()

  @enduml

HMAC process

  @startuml
  participant "Application" as App
  participant "HASH" as HASH

  == HASH initialization and Configuration ==
  App -> HASH: HAL_HASH_Init()
  note right : Configure the data type,\n key and key size
  App <-- HASH:\n\n\n
  ==  HASH process with SHA1 algorithm  ==
  group process: oneshot computing with single buffer
  App -> HASH: HAL_HMAC_SHA1_Start()
  note right : Compute and read the digest from \nthe output buffer provided via a pointer
  end
  group process: computing with several input buffers


  note right App: HAL1 does not support computing multi-buffers with HMAC process in polling mode
  App <-- HASH:\n\n\n\n\n\n\n
  end

  == HASH De-initialization  ==
  App -> HASH: HAL_HASH_DeInit()

  @enduml

Code snippet

HAL1

HAL2

/* This example is used with HASH processing */

 uint8_t Msg65_Input[65] __attribute__ ((aligned (128)))= {
 0x52, 0x43, 0x31, 0x5f, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65,
 0x61, 0x50, 0x72, 0x6f, 0x6a, 0x65,0x63, 0x74, 0x5f, 0x53,
 0x46, 0x55, 0x61, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
 0x73, 0x61,0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
 0x2d, 0x45, 0x56, 0x41, 0x4c, 0x61, 0x45, 0x57, 0x41, 0x52,
 0x4d, 0x61, 0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
 0x5f, 0x45, 0x56, 0x41, 0x4c};
 uint8_t Sha1output[20]={0};


 /* HASH Initialization and configuration */
 hhash.Init.DataType = HASH_DATATYPE_8B;
 HAL_HASH_Init(&hhash);




 /* Process with oneshot HASH computing SHA1 algorithm */




 HAL_HASH_SHA1_Start(&hhash, Msg65_Input, 65, Sha1output, 1);

 /* Process with multi-buffer updating to compute SHA1 algorithm */





 HAL_HASH_SHA1_Accmlt(&hhash, Msg65_Input, 29);
 HAL_HASH_SHA1_Accmlt(&hhash, Msg65_Input+29, 33);
 HAL_HASH_SHA1_Accmlt_End(&hhash, Msg65_Input+62, 3, Sha1output, 1);

 /* De-initialization */
 HAL_HASH_DeInit(&hhash);
/* This example is used with HASH processing */

 uint8_t Msg65_Input[65] __attribute__ ((aligned (128)))= {
 0x52, 0x43, 0x31, 0x5f, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65,
 0x61, 0x50, 0x72, 0x6f, 0x6a, 0x65,0x63, 0x74, 0x5f, 0x53,
 0x46, 0x55, 0x61, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
 0x73, 0x61,0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
 0x2d, 0x45, 0x56, 0x41, 0x4c, 0x61, 0x45, 0x57, 0x41, 0x52,
 0x4d, 0x61, 0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
 0x5f, 0x45, 0x56, 0x41, 0x4c};
 uint8_t Sha1output[20]={0};
 uint32_t sha1output_size;

 /* HASH Initialization */
 HAL_HASH_Init(&hhash, HAL_HASH);
 /* Configure SHA1 algorithm */
 hash_cfg.data_swapping  = HAL_HASH_DATA_SWAP_BYTE;
 hash_cfg.algorithm = HAL_HASH_ALGO_SHA1;
 HAL_HASH_SetConfig(&hhash, &hash_cfg);

 /* Process with oneshot HASH computing SHA1 algorithm */
 /* When the input buffer size is not a multiple of the word size,
    the last word of the message fed to the hash processor will be
    configured by considering only the valid bits specified by NBLW */

 HAL_HASH_Compute(&hhash, Msg65_Input, 65, Sha1output, 20, &sha1output_size, 1);

 /* Process with multi-buffer updating to compute SHA1 algorithm */
 /* When the input buffer size is not a multiple of the word size,
    the remaining bytes of the last word of the current message will be
    stored in the handle and processed with the next update operation */

 HAL_HASH_Update(&hhash, Msg65_Input, 29, 1);
 HAL_HASH_Update(&hhash, Msg65_Input+29, 33, 1);
 HAL_HASH_Update(&hhash, Msg65_Input+62, 3, 1);
 HAL_HASH_Finish(&hhash, Sha1output, 20, &sha1output_size, 1);
 /* De-initialization */
 HAL_HASH_DeInit(&hhash);

Key changes

  1. HAL2 uses unified HASH APIs (compute/update/finish) and selects the algorithm through a configuration function.

  2. HAL2 supports multi-buffer HMAC in polling mode, while HAL1 supports only one-shot HMAC in polling mode.